# -------------- Configuration of the Radium Engine targets and definitions ---------------------
# Setup Headless and check for dependencies

if (Headless_FOUND AND NOT TARGET Headless)
    set(Configure_Headless ON)
    # verify dependencies
    if(NOT Engine_FOUND)
        if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/../Engine/RadiumEngineConfig.cmake")
            set(Engine_FOUND TRUE)
            include(${CMAKE_CURRENT_LIST_DIR}/../Engine/RadiumEngineConfig.cmake)
        else()
            set(Radium_FOUND False)
            set(Radium_NOT_FOUND_MESSAGE "Radium::Headless: dependency Engine not found")
            set(Configure_Headless OFF)
        endif()
    endif()
    if(NOT IO_FOUND)
        if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/../IO/RadiumIOConfig.cmake")
            set(IO_FOUND TRUE)
            include(${CMAKE_CURRENT_LIST_DIR}/../IO/RadiumIOConfig.cmake)
        else()
            set(Radium_FOUND False)
            set(Radium_NOT_FOUND_MESSAGE "Radium::Headless: dependency IO not found")
            set(Configure_Headless OFF)
        endif()
    endif()
endif()

if(Configure_Headless)
    define_property(
        TARGET PROPERTY HEADLESS_HAS_GLFW BRIEF_DOCS "Radium::Headless has glfw3 support."
        FULL_DOCS "Identify if Radium::Headless was compiled with glfw3 support."
    )
    define_property(
        TARGET PROPERTY HEADLESS_HAS_EGL BRIEF_DOCS "Radium::Headless has EGL support."
        FULL_DOCS "Identify if Radium::Headless was compiled with EGL support."
    )
    include("${CMAKE_CURRENT_LIST_DIR}/HeadlessTargets.cmake")

    if(@HEADLESS_HAS_GLFW@)
        set_target_properties(Radium::Headless PROPERTIES HEADLESS_HAS_GLFW TRUE)
        if (NOT glfw3_FOUND)
            find_dependency(glfw3 3.3 REQUIRED)
        endif()
    endif()
    if(@HEADLESS_HAS_EGL@)
        set_target_properties(Radium::Headless PROPERTIES HEADLESS_HAS_EGL TRUE)
        if (NOT OpenGL_EGL_FOUND)
            find_dependency(OpenGL COMPONENTS EGL REQUIRED)
        endif()
    endif()
endif()
